﻿using System.Collections.Generic;
using NHibernate;
using NHibernate.Criterion;
using Rodunu.Movies.Contracts;
using Rodunu.Movies.Data;
using Rodunu.Movies.Interfaces.Activity;
using System.Linq;

namespace Rodunu.Movies.Logic.Activity
{
    public class UserActivityLogic : Repository<UserActivity>, IUserActivity
    {
        #region IUserActivity Members

        public IList<UserActivity> GetActivityForFriends(long userId)
        {
            ISession session = DBHelper.GetCurrentSession();
            IQuery query = session.GetNamedQuery("GetActivityForFriends");
            query.SetInt64("UserId", userId);
            return query.List<UserActivity>();
        }

        public IList<UserActivity> GetActivityForUser(long userId)
        {
            ISession session = DBHelper.GetCurrentSession();
            IList<UserActivity> userActivity = session.CreateCriteria(typeof(UserActivity))
                .Add(Expression.Like("UserInfo.Id", userId))
                .AddOrder(new Order("DateAdded", false))
                .SetMaxResults(20)
                .List<UserActivity>();
            //DBHelper.CloseSession();
            return userActivity;
        }

        #endregion
    }
}
